package leetcode.editor.week.week313;

// 6193. 沙漏的最大总和
// https://leetcode.cn/problems/maximum-sum-of-an-hourglass/
public class Solution6193 {
    public int maxSum(int[][] grid) {
        int ans = 0;
        for(int i = 0; i <= grid.length - 3 ;i++) {
            for(int j = 0; j <= grid[0].length - 3; j++) {
                ans = Math.max(ans, cal(grid, i, j));
            }
        }
        return ans;
    }

    int cal(int[][] grid, int i, int j) {
        int ans = 0;
        ans = grid[i][j] + grid[i + 2][j] + grid[i][j + 1] + grid[i][j + 2] + grid[i + 1][j + 1] + grid[i + 2][j + 1] + grid[i + 2][j + 2];
        return ans;
    }
}
